//
//  QDSicknessTypeController.m
//  simulateQuickDoctor
//
//  Created by locklight on 17/3/26.
//  Copyright © 2017年 PipiXia. All rights reserved.
//

#import "QDSicknessTypeController.h"

static NSString *illnessTypeCell = @"illnessTypeCell";

@interface QDSicknessTypeController () <UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

/**
 *  疾病类型
 */
@property (nonatomic, strong) NSArray *IllnessString;

@end

@implementation QDSicknessTypeController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNavgationBar];
    [self.view addSubview: self.tableView];
    
}

/**
 *  设置navgationBar
 */
- (void)setNavgationBar {
    UIButton *button = [[UIButton alloc] init];
    button.frame = CGRectMake(0, 0, 50, 40);
    [button setImage:[UIImage imageNamed:@"home_nav_button_back"] forState:UIControlStateNormal];
    button.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    [button addTarget:self action:@selector(didBackButton:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = leftItem;
}

/**
 *  设置返回按钮事件
 */
- (void)didBackButton:(UIButton *)button {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - UITableViewDatascoure

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.IllnessString.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:illnessTypeCell];
    
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:illnessTypeCell];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    cell.textLabel.text = self.IllnessString[indexPath.row];
    return cell;
}


#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.getTypeString) {
        self.getTypeString(self.IllnessString[indexPath.row],indexPath.row + 1);
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}


#pragma mark - 懒加载

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] init];
        _tableView.frame = self.view.bounds;
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}

- (NSArray *)IllnessString {
    if (!_IllnessString) {
        _IllnessString = @[@"肿瘤病",@"血液病",@"心脑血管病",@"神经系统",@"骨科"];
    }
    return _IllnessString;
}

@end
